<template>
   <div class="app-container">
      <el-row :gutter="24">
         <el-col :span="6" :xs="24" :sm="24" :md="12" :lg="6">
            <el-card class="profile-card">
               <template v-slot:header>
                 <div class="card-header">
                   <span class="header-title">个人信息</span>
                 </div>
               </template>
               <div class="profile-content">
                  <div class="avatar-container">
                     <userAvatar />
                  </div>
                  <div class="user-info-list">
                     <div class="info-item">
                        <div class="info-label">
                           <svg-icon icon-class="user" />
                           <span>用户名称</span>
                        </div>
                        <div class="info-value">{{ state.user.userName }}</div>
                     </div>
                     <div class="info-item">
                        <div class="info-label">
                           <svg-icon icon-class="phone" />
                           <span>手机号码</span>
                        </div>
                        <div class="info-value">{{ state.user.phonenumber }}</div>
                     </div>
                     <div class="info-item">
                        <div class="info-label">
                           <svg-icon icon-class="email" />
                           <span>用户邮箱</span>
                        </div>
                        <div class="info-value">{{ state.user.email }}</div>
                     </div>
                     <div class="info-item">
                        <div class="info-label">
                           <svg-icon icon-class="date" />
                           <span>创建日期</span>
                        </div>
                        <div class="info-value">{{ state.user.createTime }}</div>
                     </div>
                  </div>
               </div>
            </el-card>
         </el-col>
         <el-col :span="18" :xs="24" :sm="24" :md="12" :lg="18">
            <el-card class="info-card">
               <template v-slot:header>
                 <div class="card-header">
                   <span class="header-title">基本资料</span>
                 </div>
               </template>
               <el-tabs v-model="activeTab" class="custom-tabs">
                  <el-tab-pane label="基本资料" name="userinfo">
                     <userInfo :user="state.user" />
                  </el-tab-pane>
                  <el-tab-pane label="修改密码" name="resetPwd">
                     <resetPwd />
                  </el-tab-pane>
               </el-tabs>
            </el-card>
         </el-col>
      </el-row>
   </div>
</template>

<script setup name="Profile">
import userAvatar from "./userAvatar.vue";
import userInfo from "./userInfo.vue";
import resetPwd from "./resetPwd.vue";
import { getUserProfile } from "@/api/system/user";

const activeTab = ref("userinfo");
const state = reactive({
  user: {},
  roleGroup: {},
  postGroup: {}
});

function getUser() {
  getUserProfile().then(response => {
    state.user = response.data;
    state.roleGroup = response.roleGroup;
    state.postGroup = response.postGroup;
  });
};

getUser();
</script>

<style lang="scss" scoped>
.app-container {
  padding: 20px;
  background-color: var(--el-bg-color-page);
  min-height: calc(100vh - 84px);
}

.profile-card, .info-card {
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  
  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.12);
  }
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--el-border-color-light);
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--el-text-color-primary);
}

.profile-content {
  padding: 20px;
}

.avatar-container {
  display: flex;
  justify-content: center;
  margin-bottom: 24px;
}

.user-info-list {
  .info-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 0;
    border-bottom: 1px solid var(--el-border-color-lighter);
    
    &:last-child {
      border-bottom: none;
    }
    
    .info-label {
      display: flex;
      align-items: center;
      gap: 8px;
      color: var(--el-text-color-regular);
      
      svg {
        font-size: 18px;
        color: var(--el-color-primary);
      }
    }
    
    .info-value {
      font-weight: 500;
      color: var(--el-text-color-primary);
    }
  }
}

.custom-tabs {
  :deep(.el-tabs__nav-wrap::after) {
    height: 1px;
    background-color: var(--el-border-color-lighter);
  }
  
  :deep(.el-tabs__item) {
    font-size: 15px;
    padding: 0 24px;
    height: 48px;
    line-height: 48px;
    
    &.is-active {
      font-weight: 600;
    }
  }
}

@media (max-width: 768px) {
  .el-col {
    margin-bottom: 16px;
  }
  
  .profile-card, .info-card {
    margin-bottom: 16px;
  }
}
</style>
